package com.test.common.concurrency;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchExample {
    private static final int THREAD_COUNT = 5;
    private static final CountDownLatch latch = new CountDownLatch(THREAD_COUNT);

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < THREAD_COUNT; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " is running");
                latch.countDown();
            }).start();
        }
        latch.await(); // 等待所有线程执行完毕
        System.out.println("All threads have finished");
    }
}
